package com.pucheng.bracelet.ui.adapter

import android.opengl.Visibility
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.pucheng.bracelet.R

/**
@author JesseLee
@date : 2021/2/19 18:11
 */
@BindingAdapter("imageFromId")
fun bindImageFromId(view: ImageView, imageId: Int) {
    view.setImageResource(imageId)
}

@BindingAdapter("imageFromSelect")
fun bindImageFromId(view: ImageView, select: Boolean) {
    if (select) {
        view.setImageResource(R.mipmap.circle_blue_select)
    } else {
        view.setImageResource(R.mipmap.circle_blue_normal)
    }
}

@BindingAdapter("viewFromSelect")
fun bindViewBgFromSelect(view: View, select: Boolean) {
    if (select) {
        view.setBackgroundResource(R.drawable.blue_bg)
    } else {
        view.setBackgroundResource(R.drawable.white_bg)
    }
}


@BindingAdapter("viewFromSelectText")
fun bindViewBgFromSelectText(view: View, select: Boolean) {
    if (select) {
        view.setBackgroundResource(R.drawable.blue2_color_bg)
    } else {
        view.setBackgroundResource(R.drawable.white_color_bg)
    }
}

@BindingAdapter("textColorFromSelectText")
fun bindTextColorFromSelectText(view: TextView, select: Boolean) {
    if (select) {
        view.setTextColor(R.color.white)
    } else {
        view.setTextColor(R.color.colorGray)
    }
}

@BindingAdapter("viewFromSelectPush")
fun bindViewBgFromSelectPush(view: View, select: Boolean) {
    if (select) {
        view.setBackgroundResource(R.drawable.blue3_color_bg)
    } else {
        view.setBackgroundResource(R.drawable.gray1_bt_bg)
    }
}
@BindingAdapter("viewBgFromId")
fun bindViewBgFromId(view: View, id: Int) {
    view.setBackgroundResource(id)
}
@BindingAdapter("viewSrcFromId")
fun bindViewSrcFromId(view: ImageView, id: Int) {
    view.setImageResource(id)
}


@BindingAdapter("visibilityFromSelect")
fun bindImageFromId(view: View, select: Boolean) {
    if (select) {
        view.visibility = View.VISIBLE
    } else {
        view.visibility = View.GONE
    }
}

@BindingAdapter("textFromSelect")
fun bindTextFromSelect(view: TextView, select: Boolean) {
    if (select) {
        view.text = "12小时制"
    } else {
        view.text = "24小时制"
    }
}